
<template>
  <div class="bottom-bar">
    <div class="check">
      <check-button :is-checked="isSelectAll"
                    @click.native="checkClick"></check-button>
      <span>全选</span>
    </div>
    <div class="total-price">
      合计:<span>￥{{totalPrice}}</span>
    </div>
    <div class="payment">结算{{payment}}</div>

  </div>
</template>

<script>
  import CheckButton from "./CheckButton";
  import {mapGetters} from 'vuex'

  export default {
    name: "CartBottom",
    components: {CheckButton},

    computed: {
      ...mapGetters(['cartList']),
      totalPrice() {
        return this.$store.state.cartList.filter(item => {
          return item.checked
        }).reduce((preValue, item) => {
          return item.price * item.count + preValue
        }, 0).toFixed(2)
      },
      payment() {
        return this.$store.getters.cartLength
      },
      isSelectAll() {
        if (this.cartList.length === 0) return false
        return this.cartList.every(item => {
          return item.checked
        })
      }
    },
    methods: {
      checkClick() {
        if (this.isSelectAll) {
          this.cartList.forEach(item => item.checked = false)
        } else {
          this.cartList.forEach(item => item.checked = true)
        }
      }
    },
  }
</script>

<style scoped>
  .bottom-bar {
    height: 45px;
    border: 1px solid #e6e6e6;
    /*background-color: #ff5777;*/
    position: relative;
    display: flex;
    align-items: center;

  }

  .check {
    margin-left: 10px;
    display: flex;
    align-items: center;
    font-size: 17px;
  }

  .total-price {
    position: absolute;
    right: 110px;
    margin-right: 5px;
    font-size: 17px;
  }

  .total-price span {
    color: #ff5777;
    font-size: 15px;
  }

  .payment {
    position: absolute;
    height: 35px;
    width: 100px;
    background-color: #ff5777;
    border-radius: 35px;
    line-height: 35px;
    text-align: center;
    right: 5px;
  }
</style>